using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Risiko.Menu
{

  public class Button 
  {

    //public Texture2D texture;
    //public Rectangle bounds;
    //public string message;
    //public SpriteFont spriteFont;
    //public Color color;
    //public Color textColor;
    //public float scale;
    //public bool touched;
    //public Color TouchColor;
    //public bool isActive;

    public Texture2D texture { get; set; }
    public Rectangle bounds;
    public string message { get; set; }
    public SpriteFont spriteFont { get; set; }
    public Color color { get; set; }
    public Color textColor { get; set; }
    public float scale { get; set; }
    public bool touched { get; set; }
    public Color TouchColor { get; set; }
    public bool isActive { get; set; }
    
    
    public Button()
    {

    }
    
    //Costruttore con parametro scalatura del testo
    //public Button(Game game, string filepath, Rectangle bounds, Color color, string fontPath, string message, Color textColor, float scale)
    
    //{
    //  if ((filepath != null) && (filepath.Length != 0))
    //    this.texture = game.Content.Load<Texture2D>(filepath);
    //  this.bounds = bounds;
    //  this.spriteFont = game.Content.Load<SpriteFont>(fontPath);
    //  this.message = message;
    //  this.touched = false;
    //  this.color = color;
    //  this.textColor = textColor;
    //  this.scale = scale;

    //}

    ////Costruttore con parametro Color dell'effetto "premuto"
    //public Button(Game game, string filepath, Rectangle bounds, Color color, string fontPath, string message, Color textColor, Color TouchColor)
    //// : base(game)
    //{
    //  if ((filepath != null) && (filepath.Length != 0))
    //    this.texture = game.Content.Load<Texture2D>(filepath);
    //  this.bounds = bounds;
    //  this.spriteFont = game.Content.Load<SpriteFont>(fontPath);
    //  this.message = message;
    //  this.touched = false;
    //  this.TouchColor = TouchColor;
    //  this.color = color;
    //  this.textColor = textColor;
    //  this.scale = 1.0f;

    //}

    ////Costruttore con parametri base
    //public Button(Game game, string filepath, Rectangle bounds, Color color, string fontPath, string message, Color textColor)
    //// : base(game)
    //{
    //  if ((filepath != null) && (filepath.Length != 0))
    //    this.texture = game.Content.Load<Texture2D>(filepath);
    //  this.bounds = bounds;
    //  this.spriteFont = game.Content.Load<SpriteFont>(fontPath);
    //  this.message = message;
    //  this.touched = false;
    //  this.TouchColor = TouchColor;
    //  this.color = color;
    //  this.textColor = textColor;
    //  this.scale = 1.0f;
        
    //}

    //public Button(Game game, string filepath, Rectangle bounds, string fontPath, string message)
    //  : this(game, filepath, bounds, Color.White, fontPath, message, Color.Black, 1.0f) { }

    /// <summary>
    /// Funzioni che si utilizzano nel cambi0 di colore del pulsante
    /// </summary>
    
    public void changeColor(Color color)
    {
      this.color = color; 
    }
       
    public void activateButton()
    { 
        this.isActive = true;
    }

    public void dectivateButton()
    {
      this.isActive = false;
    }

    public void Touched(bool isTouched)
    {
      this.touched = isTouched;
    }

    /// <summary>
    /// Funzione che mi scrive il testo centrato all'interno del bottone
    /// </summary>
    
 
    public void DrawCenteredButton(SpriteBatch sb)
    {      
      sb.Draw(texture, bounds, null, color, 0.0f, Vector2.Zero, SpriteEffects.None, 0.9f);
      sb.DrawString(spriteFont, message, new Vector2(bounds.Center.X, bounds.Center.Y), textColor, 0.0f, spriteFont.MeasureString(message) / 2, scale, SpriteEffects.None, 1.0f);
    }

   /// <summary>
   /// Funzione che rapporta la grandezza del bottone in base al messaggio ,
   /// </summary>    
    public void ResizeButtonFromMessage()
    {       
      bounds.Width = (int)(spriteFont.MeasureString(message).X + 5);
      bounds.Height = (int)(spriteFont.MeasureString(message).Y + 5);     
    }

    /// <summary>
    /// Check if a given point is within the button bounds
    /// </summary>
    /// <param name="tapPosition">The point to check</param>
    /// <returns>True if the point is within the button bounds, false otherwise</returns>
    public bool IsInBounds(Point point)
    {
      if (bounds.Contains(point))
        return true;
      return false;
    }
  }
}
